<%@ page language="java" import="java.util.*,pojo.*,service.*,base.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>菜品查询</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap -->
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="../bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
    <style type="text/css"> 
    </style>
<script type="text/javascript" src="../jquery/jquery-1.6.1.js"></script>
<script type="text/javascript">
</script>
  </head>
  <body >
  <div class="navbar navbar-inverse navbar-fixed-top">
       <div class="navbar-inner">
           <div class="container-fluid">
              <a class="brand" href="index.jsp">白金汉宫网上订餐</a>
                    <div class="nav-collapse collapse">
                      <ul class="nav">
                        <li class="active">
                          <a href="index.jsp">主页</a>
                     </li>

                       </ul>
                             <p class="navbar-text pull-right">
    <%
        
		String username = (String)session.getAttribute( "name" );
		CartService cs= new CartService();
		if ( username == null || username == "" )
		{
	%>
<a class="navbar-link" href="login.jsp">登录</a>&nbsp;&nbsp;&nbsp;<a class="navbar-link" href="regest.jsp">注册</a>
    <%
} 
	else
	{
		int userid=(Integer)session.getAttribute("id");
		int cartNum=cs.getALL(userid);
			out.println( "欢迎您! "+username  );
			out.println("<a href='memberzone.jsp' role='button' class='btn btn-success' >个人中心</a>");
			out.println("<a href='cartlist.jsp' data-placement='bottom' role='button' class='btn btn-warning' data-toggle='tooltip' title='ffff'>我的购物车"+cartNum+"</a>");
			out.println( "<a href='destroySession.jsp' role='button' class='btn btn-danger' >安全退出</a>" );
	}
     %>
</p>
	                 </div>   
                 </div>
             </div>
         </div>
         <div class='row-fluid' style="margin-top:60px;margin-left:200px;">
         <div class='span12'> 

<%
	request.setCharacterEncoding("utf-8");
    DishesService ds = new DishesService();
    
    String select = (String)request.getParameter("select");

    int r = ds.getselectNum(select);
    
    if(r!=0){
    
    String spageno = request.getParameter("pageno");
    int pageno;//页码
    int pagesize=10;//每页显示行数
    if(spageno==null){ pageno = 1;}//当页码为空时默认为1
    
    else pageno=Integer.parseInt(request.getParameter("pageno"));//否则为传过来的页码
    String where = "where dishes.name like '"+select+"%'";
    int size=ds.getALL(where);//获取总数量
	try{pageno = Integer.parseInt(spageno);}
	catch(Exception e){}
	
		
	  	

	Page p1=new Page();
								p1.setTotalRecord(size);
								p1.setCurrentPageNo(pageno);
								p1.setPageSize(pagesize);	
	List<dishes> list = ds.selectdishes(select,pageno,pagesize);//按参数查询
	
 for (dishes inf : list) {
      out.println(" <div class='row-fluid' style='width: 800px;'><div class='span6' style='width: 100px;margin-right:50px;'>");
      out.println(" <div class='row-fluid' style='float:left;'><div class='span6' style='margin-bottom:10px;'><img src='../"+inf.getPicture()+"'class='img-polaroid' style='width:100px;height:100px;'></div><br/><div class='span6' style='text-align:center;width:100px;'><a href='dishesDetail.jsp?id="+inf.getId()+"'>"+inf.getName()+"</a></div></div></div>");
    
    }
	out.println("<div class='span12' style='margin-top:10px;float:left;margin-left: 0px;'><h5>共"+p1.getTotalPage()+"页，当前第"+pageno+"页， ---<a href='selectList.jsp?&pageno="+p1.getPrePage()+"&select="+select+"'>上一页</a>");
	out.println("<a href='selectList.jsp?&pageno="+p1.getNextPage()+"&select="+select+"'>下一页</a></h5></td></tr></div>");
	}
	
else {
     out.println("<div class='row-fluid' ><div class='span6'><div class='row-fluid' style='width:800px;'>");
     out.println("<div class='span6'><p class='text-error' style='font-weight:blod;font-size:24px;'>亲！！！您搜索的菜品不存在！！！</div>");
      out.println("<div class='span6'><p class='text-error' style='font-weight:blod;font-size:24px;'><img  src='../images/sorry.gif'></div>");
      out.println("</div></div></div>");



}
%>
</div></div>
    <script src="../bootstrap/js/bootstrap.js"></script>
    <script src="../bootstrap/js/bootstrap.min.js"></script>
  </body>
</html>
